package com.atguigu.guli.service.edu.service.impl;

import com.atguigu.guli.service.edu.controller.query.TeacherQuery;
import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.fegin.OssEduFegin;
import com.atguigu.guli.service.edu.mapper.TeacherMapper;
import com.atguigu.guli.service.edu.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2021-06-23
 */
@Service
@Slf4j
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Override
    public Page<Teacher> getPageByCondition(Page<Teacher> teacherPage, TeacherQuery query) {
        //分页查询的条件,进行查询
        QueryWrapper<Teacher> wrapper = new QueryWrapper();
        String name = query.getName();
        Integer level = query.getLevel();
        String joinDateStart = query.getJoinDateStart();
        String joinDateEnd = query.getJoinDateEnd();
        //判断条件是否为空
        if(!StringUtils.isEmpty(name)){
            wrapper.like("name", name);
        }
        if(level != null){
            wrapper.eq("level", level);
        }
        if(!StringUtils.isEmpty(joinDateStart)){
            wrapper.gt("gmt_create", joinDateStart);
        }
        if(!StringUtils.isEmpty(joinDateEnd)){
            wrapper.le("gmt_modified", joinDateEnd);
        }
        return this.page(teacherPage,wrapper);
    }


}
